<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<!--  Ak Controlller vrati 'index', prelozi sa to na /WEB-INF/views/index.jsp. Controller naplni aj premenne ${thisNode}, ${loggedIn} atd -->
<html>

<head>
<title>Gabriel Varga DSV node</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/resources/css/screen.css"/>" />
</head>

<body>
	<div id="container">
		<div class="dualbrand">
			<img src="/static/resources/gfx/fit.png" />
		</div>
		<div id="content">
		
			<h1>Welcome to DSV RMI Generic node!</h1>
			<form:form commandName="shared" id="reg">
				<h2>Controls</h2>
				<c:choose>
					<c:when test="${loggedIn == true}">
						<table>
							<tbody>
								<tr>
									<td><form:label path="sharedProperty">Name:</form:label></td>
									<td><form:input path="sharedProperty" /></td>
								</tr>
							</tbody>
						</table>
					</c:when>
				</c:choose>
				
				<table>
					<tr>
						<c:choose>
							<c:when test="${loggedIn == true}">
								<td><input type="submit" name="write" value="Write" /></td>

								<td><input type="submit" name="read" value="Read" /></td>

								<td><input type="submit" name="logout" value="Logout" /></td>
							</c:when>
							<c:otherwise>
								<td><input type="submit" name="login" value="Login" /></td>
							</c:otherwise>
						</c:choose>
					</tr>
				</table>
			</form:form>

			<h2>Zakladne udaje</h2>
			<table class="simpletablestyle lessWidth">
				<tr>
					<td>Meno</td>
					<td>${thisNode.name}</td>
				</tr>
				<tr>
					<td>IP</td>
					<td>${thisNode.ipAddress}:${thisNode.port}</td>
				</tr>
				<tr>
					<td>Url</td>
					<td><a href="<c:url value="../${thisNode.url}"/>" target="_blank" />Odkaz</td>
				</tr>

			</table>

			<h2>Zakladne udaje servra</h2>
			<table class="simpletablestyle lessWidth">
				<tr>
					<td>Meno</td>
					<td>${rmiServer.name}</td>
				</tr>
				<tr>
					<td>IP</td>
					<td>${rmiServer.ipAddress}:${rmiServer.port}</td>
				</tr>
				<tr>
					<td>Url</td>
					<td><a href="<c:url value="../${rmiServer.url}"/>" target="_blank" />Odkaz</td>
				</tr>
			</table>

			<h2>Ostatne Uzly</h2>
			<c:choose>
				<c:when test="${rmiNodes.isEmpty()}">
					<em>No other registered RMI nodes.</em>
				</c:when>
				<c:otherwise>
					<table class="simpletablestyle">
						<thead>
							<tr>
								<th>Name</th>
								<th>IP adress</th>
								<th>Url</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${rmiNodes}" var="rmiNode">
								<tr>
									<td>${rmiNode.name}</td>
									<td>${rmiNode.ipAddress}:${rmiNode.port}</td>
									<td><a target="_blank" href="<c:url value="../${rmiNode.url}"/>">Odkaz</a></td>
							</c:forEach>
						</tbody>
					</table>
				</c:otherwise>
			</c:choose>
			
			<h2>Log</h2>
			<table class="simpletablestyle ">
				<thead>
					<tr>
						<th>Date</th>
						<th>Text</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${logs}" var="log">
						<tr>
							<td>${log.timeMillis}</td>
							<td>${log.text}</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<a target="_blank" href="<c:url value="/report"/>">Log ako PDF</a>
		</div>
		<div id="footer">
			<p>Projekt MI-DSV, Gabriel Varga, vargagab@fit.cvut.cz</p>
		</div>
	</div>
</body>
</html>
